package com.dqyt.khjc.controller;

import com.dqyt.khjc.bean.ResultMsg;
import com.dqyt.khjc.service.CustomerUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 客户人员信息
 */
@RestController
public class CustomerUserController {

    @Autowired
    private CustomerUserService examinationService;

    /**
     * 分页查询 待审核的 客户人员信息
     * @param request
     * @param page
     * @param size
     * @param name
     * @param phone
     * @param customerId
     * @param dtype
     * @return
     */
    @RequestMapping("/api/getReviewApplys")
    public ResultMsg getReviewApplyList(HttpServletRequest request,
                                        @RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer size,
                                        @RequestParam(name = "name", required = false, defaultValue = "") String name,
                                        @RequestParam(name = "phone", required = false, defaultValue = "") String phone,
                                        @RequestParam(name = "customerId", required = false, defaultValue = "-1") String customerId,
                                        @RequestParam(name = "dtype", required = false, defaultValue = "-99") String dtype
    ) {
        ResultMsg resultMsg = examinationService.getReviewApplyList(request, page, size, name, phone, customerId, dtype);
        return resultMsg;
    }

    /**
     * 批量同意
     *
     * @param ids id 集合
     * @return
     */
    @RequestMapping("/api/batchHandle")
    public ResultMsg batchHandle(HttpServletRequest request, @RequestParam(required = true) int[] ids,int [] cuids, String statue,String [] names) {
        ResultMsg resultMsg = examinationService.batchHandle(request, ids, statue,names,cuids);
        return resultMsg;
    }


    /**
     * 批量拒绝
     *
     * @param ids id 集合
     * @return
     */
    @RequestMapping("/api/batchRefuse")
    public ResultMsg batchRefuse(HttpServletRequest request, @RequestParam(required = true) int[] ids, String refuseReason,String [] names) {
        ResultMsg resultMsg = examinationService.batchRefuse(request, ids, refuseReason,names);
        return resultMsg;
    }

    /**
     *
     * @param userName  客户人员名称
     * @param phone   客户人员手机
     * @param customerId 客户id
     * @param account  客户人员账号
     * @param password  客户人员密码
     * @param password2  确认密码
     * @param isopen   是否为默认联系人
     * @param enterpriseName  所属机构的名字
     * @return
     */
    @RequestMapping(value = "/api/addCustomerUser", method = {RequestMethod.POST})
    public  ResultMsg addCustomerUser(HttpServletRequest request,String userName,String phone,int customerId,
                                      @RequestParam(defaultValue = "0") Integer chId,
                                      String account,String password ,String password2,boolean isopen,String enterpriseName){

        ResultMsg resultMsg = examinationService.addCustomerUser(request, userName, phone,customerId,chId,account,password,password2,isopen,enterpriseName);
        return resultMsg;
    }



    /**
     * 修改
     * @param userName  客户人员名称
     * @param phone   客户人员手机
     * @param customerId 客户id
     * @param account  客户人员账号
     * @return
     */
    @RequestMapping(value = "/api/updateCustomerUser", method = {RequestMethod.POST})
    public  ResultMsg updateCustomerUser(HttpServletRequest request,long customerUserId,String userName,String phone,int customerId,
                                         @RequestParam(defaultValue = "0") Integer chId,
                                      String account){

        ResultMsg resultMsg = examinationService.updateCustomerUser(request,customerUserId, userName, phone,customerId,chId,account);
        return resultMsg;
    }


    /**
     * 分页查询 审核通过的客户人员信息
     * @param request
     * @param page
     * @param size
     * @param userName
     * @param phone
     * @param customerId
     * @return
     */
    @RequestMapping("/api/getKhryxxApplys")
    public ResultMsg getKhryxxApplys(HttpServletRequest request,
                                        @RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10") Integer size,
                                        @RequestParam(name = "userName", required = false, defaultValue = "") String userName,
                                        @RequestParam(name = "phone", required = false, defaultValue = "") String phone,
                                        @RequestParam(name = "customerId", required = false, defaultValue = "-1") String customerId,
                                        @RequestParam(defaultValue = "0") Integer chId
    ) {
        ResultMsg resultMsg = examinationService.getKhryxxApplys(request, page, size, userName, phone, customerId,chId);
        return resultMsg;
    }


    /**
     * 登陆限制 客户信息
     * @param customerUserId 客户人员id
     * @param statue   1:允许登陆    2:限制登录
     * @return
     */
    @RequestMapping(value = "/api/loginKxryxxRes", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg loginKxryxxRestrictions(HttpServletRequest request,long customerUserId,int statue,String userName){
        ResultMsg resultMsg = examinationService.loginKxryxxRes(request,customerUserId,statue,userName);
        return resultMsg;
    }

    /**
     * 查询所属机构下面的人员列表
     * @param request
     * @param customerId
     * @return
     */
    @RequestMapping(value = "/api/getCuUsersByCuId", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg getCuUsersByCuId(HttpServletRequest request,int customerId){
        ResultMsg resultMsg = examinationService.getCuUsersByCuId(request,customerId);
        return resultMsg;
    }


}
